﻿using H2.NET.Common;
using H2.NET.Data.Common;
using H2.NET.Web.Management.Config.Service;
using H2.NET.Web.Pages.SMD.Model;
using H2.NET.Web.Pages.SMD.Service;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace H2.NET.Web.Pages.SMD
{
    public partial class uc_store_info : System.Web.UI.UserControl
    {
        public string guid = Guid.NewGuid().ToString().Replace("-", "");
        public t_smd_Store store
        {
            get
            {
                return ViewState["store"] == null ? new t_smd_Store() : (t_smd_Store)ViewState["store"];
            }
            set
            {
                ViewState["store"] = value;
            }
        }
        public bool IsCanEditAuthID
        {
            get
            {
                return ViewState["IsCanEditAuthID"] == null ? true : (bool)ViewState["IsCanEditAuthID"];
            }
            set
            {
                ViewState["IsCanEditAuthID"] = value;
            }
        }
        public string AllRegion
        {
            get 
            {
                return ViewState["AllRegion"] == null ? "" : (string)ViewState["AllRegion"];
            }
            set 
            {
                ViewState["AllRegion"] = value;
            }
        }
        public string StrId
        {
            get
            {
                return ViewState["StrId"] == null ? "storeid" : (string)ViewState["StrId"];
            }
            set
            {
                ViewState["StrId"] = value;
            }
        }
        public string Title
        {
            get
            {
                return ViewState["Title"] == null ? "门店信息" : (string)ViewState["Title"];
            }
            set
            {
                ViewState["Title"] = value;
            }
        }

        public string isNew
        {
            get
            {
                return ViewState["isNew"] == null ? "" : (string)ViewState["isNew"];
            }
            set
            {
                ViewState["isNew"] = value;
            }
        }

        public bool IsShowDeivceList
        {
            get
            {
                return ViewState["IsShowDeivceList"] == null ? true : (bool)ViewState["IsShowDeivceList"];
            }
            set
            {
                ViewState["IsShowDeivceList"] = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            switch (isNew) 
            {
                case "new":
                    t_Dealer.Text = "转入经销商信息";
                    Title = "转入门店信息";
                    break;
                case "old":
                    t_Dealer.Text = "转出经销商信息";
                    Title = "转出门店信息";
                    break;
                default:
                    break;
            }
            uc_search_store1.AllRegion = AllRegion;
            if (!IsPostBack)
            {
                uc_search_store1.StrId = StrId;

                if (store != null && !string.IsNullOrEmpty(store.AuthID))
                {
                    if (store.DealerID != null)
                    {
                        var dealer = DealerService.GetById(store.DealerID.Value);

                        dealer_dealerCode_label.Text = dealer.DealerCode;
                        dealer_name_label.Text = dealer.Name;
                        dealer_region_label.Text = dealer.Region;
                        dealer_province_label.Text = dealer.Province;
                        dealer_cityName_label.Text = dealer.CityName;
                    }

                    tb_authId.Text = store.AuthID.ToString();

                    l_storeStatus.Text = store.StoreStatus;
                    l_store_type.Text = store.StoreType;
                    l_NewFitment.Text = store.NewFitment;
                    l_region.Text = store.Region;
                    l_province.Text = store.Province;
                    l_cityName.Text = store.CityName;
                    l_cityClass.Text = store.CityClass;
                    l_store_name.Text = store.StoreName;
                    l_ContractPerson.Text = store.ContactPerson;
                    l_Telephone.Text = store.PhoneNumber;
                    l_address.Text = store.StoreAddress;
                    l_EapproveSN.Text = store.EapproveSN;

                    if (IsShowDeivceList)
                    {
                        var list = (v_DeviceDeposit._StoreID == store.StoreID).List<v_DeviceDeposit>(Storage.Context3);
                        if (list == null || list.Count == 0)
                        {
                            tr_empty.Visible = true;
                        }
                        rpt_deivce_deposit.DataSource = list;
                        rpt_deivce_deposit.DataBind();

                        device_list.Visible = true;
                    }

                    if (!IsCanEditAuthID)
                    {
                        tb_authId.Visible = false;

                        tb_authId_label.Text = store.AuthID.ToString();
                    }
                }
            }
        }

    }
}